package org.marverse.scripting

import ScriptingUtil._

sealed abstract case class UncheckedTypedExpr(val base: UncheckedExpression, val expectedType: Type) extends UncheckedExpression {

}

object UncheckedTypedExpr {
  def apply(base: UncheckedExpression, expectedType: Type): UncheckedTypedExpr = 
    new UncheckedTypedExprImpl(base, expectedType)
}

private class UncheckedTypedExprImpl(base: UncheckedExpression, expectedType: Type)
extends UncheckedTypedExpr(base, expectedType) {
  
  override def childUncheckedExpressions = Seq.empty
  override def checked(implicit ctx: MutableTypedMap[TypedKey, Any]) = {
    val i = base.checked
    if (expectedType <:: i.expressionType)
      new TypeErrorExpr(i, expectedType)
    else 
      i
  }

}
